home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / SparksDemo.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  2.7 KB  |  161 lines

  1. ' Sparks Demo
  2. ' Written by Scott Brosious
  3.  
  4. const width = 200, height = 200
  5. const nops = 1000         ' Number of pixels
  6. const Speed = 1           ' Speed   
  7.  
  8. dim xcntr,ycntr
  9.  
  10. xcntr = width / 2    
  11. ycntr = height / 2   
  12.  
  13. const scale = 3
  14.  
  15. dim buffer(width)(height)
  16.  
  17. dim col1#
  18. dim col2#
  19. dim texture
  20. dim a   
  21. dim i,j 
  22. dim time  ' Current time
  23. dim t1,t2 ' Starting and ending time variables
  24.  
  25. dim xpos(nops) ' Xposition
  26. dim ypos(nops) ' Yposition
  27. dim ang(nops)  ' Angles
  28. dim st(nops)   ' Start time
  29. dim et(nops)   ' End time
  30. dim mt(nops)   ' Time to move
  31.  
  32. for i = 1 to nops
  33.  
  34. gosub Inittime
  35.  
  36. st(i) = t1
  37. et(i) = t2
  38.  
  39. gosub Angles
  40.  
  41. ang(i) = a
  42.  
  43. next
  44.  
  45. ' Set 2D mode
  46. glMatrixMode (GL_PROJECTION)
  47. glLoadIdentity ()
  48. glOrtho (0, width, 0, height, -1, 1)
  49. glMatrixMode (GL_MODELVIEW)
  50. glDisable (GL_DEPTH_TEST)
  51.  
  52. texture = LoadTexture ("data\fb01.png")
  53.  
  54. glEnable (GL_TEXTURE_2D)    
  55.  
  56. ' Translucency, Blending
  57. glBlendFunc(GL_SRC_ALPHA,GL_ONE)
  58. glEnable(GL_BLEND)
  59.  
  60. while true    
  61.  
  62. ' Clear screen   
  63. glClear (GL_COLOR_BUFFER_BIT)   
  64.  
  65. glBindTexture (GL_TEXTURE_2D, texture)
  66.  
  67. for i = 1 to nops
  68.  
  69. if time > st(i) then mt(i) = mt(i) + 1 :endif ' If current time greater then start time then move it.
  70.  
  71. if mt(i) > et(i) then gosub Refresh :endif ' If movetime greater then endtime start again
  72.  
  73. xpos(i)= xcntr + cosd(ang(i)) * (mt(i) * Speed)
  74. ypos(i)= ycntr + sind(ang(i)) * (mt(i) * Speed)
  75.  
  76. if xpos(i) < 0 or xpos(i) > width then goto skip1 endif
  77. if ypos(i) < 0 or ypos(i) > height then goto skip1 endif
  78.  
  79. buffer(xpos(i))(ypos(i)) = 10
  80.  
  81. skip1:       
  82.  
  83. next 
  84.  
  85. for j = 0 to height
  86. for i = 0 to width
  87.  
  88. buffer(i)(j) = buffer(i)(j) - 1
  89.  
  90. next  
  91. next
  92.  
  93.  
  94. glBegin (GL_QUADS)
  95.  
  96. for j = 0 to height
  97. for i = 0 to width
  98.  
  99. col1# = buffer(i)(j)
  100.  
  101. if col1# < 0 then goto skip2 endif
  102. if col1# > 10 then col1# = 10 endif
  103.  
  104. col2# =  col1# / 10
  105.  
  106.       glColor4f (1, 1, 1, col2#)
  107.  
  108.       glTexCoord2f (0, 1)                         
  109.       glVertex2f (i - scale,j + scale)     ' Top left
  110.  
  111.       glTexCoord2f (0, 0)                         
  112.       glVertex2f (i - scale,j - scale)     ' Bottom left
  113.             
  114.       glTexCoord2f (1, 0)                         
  115.       glVertex2f (i + scale,j - scale)     ' Bottom right    
  116.  
  117.       glTexCoord2f (1, 1)                         
  118.       glVertex2f (i + scale,j + scale)     ' Top right
  119.  
  120. skip2:
  121.  
  122. next
  123. next
  124.  
  125. glEnd ()
  126.  
  127. ' Display output
  128. SwapBuffers ()
  129.  
  130. time = time + 1
  131.  
  132. wend
  133.  
  134. ReFresh:
  135.  
  136. gosub InitTime  
  137. st(i) = t1
  138. et(i) = t2
  139. mt(i) = 0
  140. gosub Angles
  141. ang(i) = a
  142.  
  143. return
  144.  
  145. InitTime:
  146.  
  147. t1 = rnd() % 20 
  148. t2 = rnd() % width
  149.  
  150. return              
  151.  
  152. Angles:
  153.  
  154. a = rnd() % 360
  155.  
  156. return
  157.  
  158.  
  159.  
  160.  
  161.